Skip to content

ClickHouse: Support ON CLUSTER and SETTINGS in DELETE and UPDATE - #2617

Open
jordiori wants to merge 6 commits into
apache:mainfrom
jordiori:clickhouse-delete-update-cluster-settings
Open

jordiori wants to merge 6 commits into
apache:mainfrom
jordiori:clickhouse-delete-update-cluster-settings

Conversation

@jordiori

@jordiori jordiori commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Dialects: ClickHouse

These ClickHouse statements failed to parse:

DELETE FROM hits ON CLUSTER c1 WHERE x = 1 SETTINGS lightweight_deletes_sync = 0
UPDATE hits ON CLUSTER c1 SET x = 1 WHERE y = 2 SETTINGS update_parallel_mode = 'auto'

This adds on_cluster and settings to Delete and Update. ON CLUSTER is parsed the same way as in other ClickHouse statements. SETTINGS is only accepted by dialects where supports_settings() is true.

Also, see code with references to SETTINGS:

@codecov-commenter

codecov-commenter commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.05085% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.17%. Comparing base (dacdbc9) to head (3344ef3).

Files with missing lines Patch % Lines
src/ast/dml.rs 50.00% 0 Missing and 8 partials ⚠️
src/ast/spans.rs 94.28% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2617   +/-   ##
=======================================
  Coverage   81.16%   81.17%           
=======================================
  Files          42       42           
  Lines       33769    33826   +57     
  Branches    33769    33826   +57     
=======================================
+ Hits        27408    27457   +49     
  Misses       2797     2797           
- Partials     3564     3572    +8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

Please add examples of this syntax to the fuzzer corpus.

@LucaCappelletti94 LucaCappelletti94 added enhancement New feature or request waiting on contributor The review needs further refinements by its author labels Oct 12, 2026
@jordiori
jordiori force-pushed the clickhouse-delete-update-cluster-settings branch from f4031df to 6951f1e Compare October 13, 2026 07:24
@jordiori

Copy link
Copy Markdown
Contributor Author

Please add examples of this syntax to the fuzzer corpus.

done! @LucaCappelletti94

@LucaCappelletti94 LucaCappelletti94 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should link the ClickHouse sources for the new syntax in the description.

Comment thread src/ast/spans.rs

target.span().union(&value.span())
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should give Setting its own Spanned impl, as Assignment has, so its span is defined once and not spelled out in every statement that carries SETTINGS.

Suggested change
}
impl Spanned for Setting {
fn span(&self) -> Span {
let Setting { key, value } = self;
key.span.union(&value.span())
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thanks :)

Comment thread tests/sqlparser_clickhouse.rs Outdated
Comment on lines +2264 to +2267
assert!(all_dialects_where(|d| !d.supports_settings())
.parse_sql_statements("DELETE FROM hits WHERE x = 1 SETTINGS a = 1")
.is_err());
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should assert the expected error, as the cases above do. is_err() also passes when the statement fails before SETTINGS is reached.

Suggested change
assert!(all_dialects_where(|d| !d.supports_settings())
.parse_sql_statements("DELETE FROM hits WHERE x = 1 SETTINGS a = 1")
.is_err());
}
assert_eq!(
all_dialects_where(|d| !d.supports_settings())
.parse_sql_statements("DELETE FROM hits WHERE x = 1 SETTINGS a = 1")
.unwrap_err(),
ParserError("Expected: end of statement, found: SETTINGS".to_string())
);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thanks :)

Comment thread tests/sqlparser_clickhouse.rs Outdated
Comment on lines +2322 to +2324
assert!(all_dialects_where(|d| !d.supports_settings())
.parse_sql_statements("UPDATE hits SET x = 1 WHERE y = 2 SETTINGS a = 1")
.is_err());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should assert the expected error, as the cases above do. is_err() also passes when the statement fails before SETTINGS is reached.

Suggested change
assert!(all_dialects_where(|d| !d.supports_settings())
.parse_sql_statements("UPDATE hits SET x = 1 WHERE y = 2 SETTINGS a = 1")
.is_err());
assert_eq!(
all_dialects_where(|d| !d.supports_settings())
.parse_sql_statements("UPDATE hits SET x = 1 WHERE y = 2 SETTINGS a = 1")
.unwrap_err(),
ParserError("Expected: end of statement, found: SETTINGS".to_string())
);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ClickHouse enhancement New feature or request waiting on contributor The review needs further refinements by its author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants